import 'package:flutter/material.dart';
import 'package:flutter_base_library/app/themes/app_colors.dart';
import 'package:flutter_base_library/app/utils/date_time_utils.dart';
import 'package:get/get.dart';
import 'package:safe_manage/widgets/info_content_item.dart';
import 'alarm_picture_info_controller.dart';

class AlarmPictureInfoPage extends StatelessWidget {
  final controller = Get.find<AlarmPictureInfoController>();
  AlarmPictureInfoPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("事件详情"),
      ),
      body: Container(
        width: Get.width,
        color: const Color(0xFFEFEFF4),
        child: _bodyContent(context),
      ),
    );
  }

  Widget _bodyContent(BuildContext context) {
    return ListView(
      children: [
        const SizedBox(height: 20),
        _infoContent(),
        const SizedBox(height: 20),
        _pictureContent(context),
        _videoContent(context),
      ],
    );
  }

  Widget _infoContent() {
    return Container(
      padding: const EdgeInsets.fromLTRB(15, 10, 15, 10),
      width: Get.width,
      color: Colors.white,
      child: Column(
        children: [
          InfoContentItem("部门名称", controller.bumen),
          InfoContentItem(
            "巡检类型",
            controller.picture.xjlx ?? "",
          ),
          InfoContentItem(
            "事件时间",
            () {
              int? milliseSecond = controller.picture.cjsj?.toInt();
              if (milliseSecond != null) {
                DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
                  milliseSecond * 1000,
                );
                return toLocalDateTimeByDateTime(dateTime);
              }
              return "";
            }(),
          ),
        ],
      ),
    );
  }

  Widget _pictureContent(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),
      padding: const EdgeInsets.fromLTRB(15, 10, 15, 20),
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            "记录截图",
            style: TextStyle(
              color: Color(0xFF6C6C6C),
              fontSize: 18,
            ),
          ),
          const SizedBox(height: 10),
          Row(
            children: [
              Container(
                // padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
                child: controller.imgUrl.isEmpty
                    ? Container()
                    : GestureDetector(
                        onTap: () {
                          controller.showImgDetails(context);
                        },
                        child: Image.network(
                          controller.imgUrl,
                          fit: BoxFit.fill,
                          width: 70,
                          height: 70,
                        ),
                      ),
              ),
            ],
          ),
          const SizedBox(height: 10),
          const Text(
            "点击查看大图",
            style: TextStyle(
              color: Color(0xFF9A9A9A),
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }

  Widget _videoContent(BuildContext context) {
    return Container(
      margin: const EdgeInsets.fromLTRB(0, 10, 0, 0),
      padding: const EdgeInsets.fromLTRB(15, 10, 15, 20),
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            "记录视频",
            style: TextStyle(
              color: Color(0xFF6C6C6C),
              fontSize: 18,
            ),
          ),
          const SizedBox(height: 10),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // const Icon(
              //   Icons.video_file,
              //   size: 40,
              //   color: AppColors.kPrimaryColor,
              // ),
              // const SizedBox(width: 10),
              Expanded(
                child: GridView.builder(
                  shrinkWrap: true,
                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3,
                    // mainAxisSpacing: 10,
                    crossAxisSpacing: 10,
                    mainAxisExtent: 40,
                  ),
                  itemCount: controller.videoList.length,
                  itemBuilder: (BuildContext context, int index) {
                    return GestureDetector(
                      onTap: () {
                        controller.videoClicked(index);
                      },
                      behavior: HitTestBehavior.translucent,
                      child: Container(
                        margin: const EdgeInsets.fromLTRB(0, 5, 0, 5),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(5),
                          border: Border.all(color: AppColors.kPrimaryColor),
                        ),
                        alignment: Alignment.center,
                        child: Text(
                          "查看视频${index + 1}",
                          style: const TextStyle(
                            color: Color(0xFF101010),
                            fontSize: 14,
                          ),
                        ),
                      ),
                    );
                  },
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
